package cc.web;

import cc.entity.User;

import cc.entity.UserPassowrdEdit;

import cc.service.IUserService;

import io.swagger.annotations.*;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;



/**

 * TODO

 *

 * @author My

 * @date 2021/10/11 11:00

 */

@RestController

@RequestMapping("/user")

@Api(tags = "用户模块接口规范说明")

public class UserController {



    @Autowired

    IUserService userService;



    @ApiOperation(value = "问候")

    @GetMapping("/get")

    public String greeting() {

        return "cc so ...hhh";

    }



    @GetMapping("/getById/{id}/{name}")

    public User getById(@PathVariable("id") Integer id,@PathVariable("name") String name) {

        User user = new User();

        user.setId(id);

        user.setName(name);

        return user;

    }





    @ApiOperation(value = "根据用户id和姓名返回用户信息",

            notes = "span style='color:red;'>描述:</span>&nbsp;用于根据用户id和姓名返回用户信息")

    @GetMapping("/getByIds")

    @ApiImplicitParams({

            @ApiImplicitParam(name = "id",value = "用户id",dataType = "Integer",defaultValue = "1"),

            @ApiImplicitParam(name = "name",value = "用户姓名",dataType = "String",defaultValue = "张三")

    })

    public User getByIds(@RequestParam("id") Integer id,@RequestParam("name") String name) {

        User user = new User();

        user.setId(id);

        user.setName(name);

        return user;

    }



    @PostMapping("/getByIdss")

    public User getByIdss(Integer id) {

        User user = new User();

        user.setId(id);

        user.setName("张三");

        return user;

    }



    @PostMapping("/add")

    public User add(@RequestBody User user) throws Exception {

        userService.save(user);

        return user;

    }



    @GetMapping("/getByIdFromDb/{id}")

    public User getByIdFromDb(@PathVariable("id") Integer id) throws Exception {

        User user = userService.getById(id);

        return user;

    }



    @GetMapping("/getByIdFromDb2")

    public User getByIdFromDb2(@RequestParam("id") Integer id) throws Exception {

        User user = userService.getById2(id);

        return user;

    }



    @ApiOperation(value = "修改用户密码",

            notes = "修改用户密码")

    @ApiResponses({

            @ApiResponse(code=400,message = "请求参数没填好"),

            @ApiResponse(code=404,message = "请求路径没有"),

            @ApiResponse(code=200,message = "成功")

    })

    @PostMapping("/passwordEdit")

    public User passwordEdit(@RequestBody UserPassowrdEdit userPassowrdEdit){



        User user = userService.update(userPassowrdEdit);

        return user;

    }

}

